<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currenTab">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><UserFilled /></el-icon>
            账号登陆
          </span>
        </template>
        <login-account ref="accountRef"></login-account>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Phone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <login-phone ref="phoneRef"></login-phone>
      </el-tab-pane>
    </el-tabs>
    <div class="control">
      <el-checkbox ref="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="onTime" @click="handleLoginCheck"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import { UserFilled, Phone } from '@element-plus/icons-vue'

export default defineComponent({
  setup() {
    const currenTab = ref('account')
    const isKeepPassword = ref(true)
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const phoneRef = ref<InstanceType<typeof LoginPhone>>()
    const handleLoginCheck = () => {
      if (currenTab.value == 'account') {
        accountRef.value?.loginAction(isKeepPassword.value)
      } else {
        console.log('调用phone')
      }
    }
    return {
      currenTab,
      phoneRef,
      isKeepPassword,
      handleLoginCheck,
      accountRef
    }
  },
  components: {
    UserFilled,
    Phone,
    LoginPhone,
    LoginAccount
  }
})
</script>

<style lang="less" scoped>
.login-panel {
  width: 320px;
  margin-bottom: 120px;
  .title {
    text-align: center;
  }
  .control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .onTime {
    margin-top: 5px;
    width: 100%;
  }
}
</style>
